define(['common', 'toastr', 'md5', 'jqueryValidationZh'], function(common, toastr, md5) {
    return {
        init: function() {
            $("#editPassForm").validate({
                rules: {
                    pass1: 'required',
                    pass2: 'required',
                    pass3: {
                        required: true,
                        equalTo: '#pass2'
                    }
                },
                messages: {
                    pass1: '请填写原始密码',
                    pass2: '请填写修改后的密码',
                    pass3: {
                        required: '请再次填写修改后的密码',
                        equalTo: '两次输入的密码不一致'
                    }
                },
                submitHandler: function(from) {
                    var pass1 = $("#pass1").val();
                    var pass2 = $("#pass2").val();
                    common.handleAjax('resetPass', { pass1: md5(pass1), pass2: md5(pass2) }, true, true).done(function(result) {
                        if (result.code === -4) {
                            return;
                        }
                        if (result.code === -1) {
                            layer.alert('数据异常，保存失败。');
                            return;
                        }
                        if (result.code === 1) {
                            toastr.success(result.msg);
                            from.reset();
                        } else {
                            toastr.error(result.msg);
                        }
                    });
                }
            });

        }
    }
});